package ioperations;

import book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-31
 * Time: 16:16
 */
public class ReturnOperation implements IOperations{
    @Override
    public void work(BookList bookList) {
        System.out.println("归还图书");
        System.out.println("请输入您要归还的图书的名字：");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();
        for (int i = 0; i < bookList.usedSize; i++) {
            if(bookList.books[i].getName().equals(name)) {
                if(bookList.books[i].isBorrowed()) {
                    bookList.books[i].setBorrowed(false);
                    System.out.println("归还成功");
                    return;
                }
                System.out.println("该书还未被借出");
                return;
            }
        }
        System.out.println("该书不在本系统中");
    }
}
